package com.credithc.signature.manager.controller.api;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.signature.common.ro.manager.ChannelRo;
import com.credithc.signature.common.service.ChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/scs/v2")
@Slf4j
public class ChannelApiController {

    @Autowired
    private MessageFactory messageFactory;

    @Autowired
    ChannelService channelService;


    /**
     * 新增--对外提供
     *
     * @param channelRo
     * @return
     */
    @PostMapping("/channel/save")
    public Message save(@RequestBody @Valid ChannelRo channelRo) {
        try {
            channelService.save(channelRo);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, "渠道信息保存成功！");
        } catch (Exception e) {
            log.error("对外提供渠道保存接口发生异常", e);
            return messageFactory.getInstance(CoreCodes.CORE_SYS_ERROR, "渠道信息保存失败: " + e.getCause());
        }
    }

    /**
     * 修改--对外提供
     *
     * @param channelRo
     * @return
     */
    @PostMapping("/channel/updata")
    public Message updata(@RequestBody @Valid ChannelRo channelRo) {
        try {

            channelService.update(channelRo);
            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, "渠道信息修改成功！");
        } catch (Exception e) {
            log.error("对外提供渠道更新接口发生异常", e);
            return messageFactory.getInstance(CoreCodes.CORE_SYS_ERROR, "渠道修改失败: " + e.getCause());
        }
    }

//    /**
//     * 删除--对外提供
//     *
//     * @param channelRo
//     * @return
//     */
//    @PostMapping("/channel/del")
//    public Message del(@RequestBody @Valid ChannelRo channelRo) {
//        try {
//            channelService.del(channelRo);
//            return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, "渠道信息修改成功！");
//        } catch (Exception e) {
//            log.error("对外提供渠道删除接口发生异常", e);
//            return messageFactory.getInstance(CoreCodes.CORE_SYS_ERROR, "渠道修改失败: " + e.getCause());
//        }
//    }
}
